#ifndef Pad_H
#define Pad_H
#include <QObject>
#include <qsignalmapper.h>
#include <QStringList>
#include <QHash>

#include <indiapi.h>
#include <basedevice.h>
#include <baseclient.h>
#include <inditelescope.h>
#include <QPushButton>

namespace Ui {
  class Pad;
}

typedef struct coord {
  double ra;
  double dec;
} coord_t;


class Pad;

typedef  void (Pad::*PadFn)(int value);
#define CALL_MEMBER_FN(object,ptrToMember)  ((object).*(ptrToMember))

class PadButtonEvent: public QObject {
  Q_OBJECT

public:
  PadButtonEvent(Pad *, QString, QPushButton *);
  PadButtonEvent(Pad *, QString, PadFn);
  QString getLabel();
  QPushButton *getButton();
  void activate(int);
protected:
  Pad *pad;
  QString label;
  QPushButton *button;
  QHash<QString, PadFn> padcallbacks;
};

class Pad: public QObject {
  Q_OBJECT

  enum direction {NORTH, SOUTH, EAST, WEST};

signals:
  void lastgotosynced(double tra, double tdec);
  
public slots:
  void setTelescope(INDI::BaseDevice *);
  void pressdirection(int);
  void changespeed(int);
  void changespeed(QString);
  void setSpeedIndex(int);
  void abortmotion();
  void incspeed(int);
  void decspeed(int);
  void setJoypadActive(bool);
  void syncLast();
  void addGoto(double ra, double dec);
 
public:
  Pad(INDI::BaseClient *);
  void setupUi(QWidget *parent);
  QHash<QString, PadButtonEvent *> getPadButtonEvents();
  bool getJoypadActive();
 
private:
  void makeConnections();
  void makeDefaultPresetSpeeds();
protected:
  INDI::BaseClient *client;
  Ui::Pad *ui;
  INDI::Telescope *telescope;
private:  
  QSignalMapper *dirsignalMapper;
  static double presetspeeds[] ;
  //static QString *presetspeedslabels[10];
  QStringList *presetspeedslabels;
  QHash<QString, PadButtonEvent *> padbuttonevents;
  bool isJoypadActive;
  QList<coord_t> gotos;
};

#endif // Pad_H